home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.024.Teach / teach.aii / umenu.aii < prev    next >
Encoding:
Text File  |  1990-06-24  |  9.2 KB  |  592 lines  |  [TEXT/MPS ]

  1. ***********************************************************************
  2. *
  3. * teach umenu.aii -- Version 3.0
  4. *
  5. * Copyright (c)
  6. * Apple Computer, Inc.  1986-1990
  7. * All Rights Reserved.
  8. *
  9. * Developer Technical Support Apple II Sample Code
  10. *
  11. * This file contains the code which implements  
  12. * windows in the busybox program.
  13. *
  14. ***********************************************************************
  15.  
  16.     case  on
  17.     longi on
  18.     longa on
  19.  
  20.     INCLUDE 'e16.types'
  21.     INCLUDE 'm16.control'
  22.     INCLUDE 'm16.desk'
  23.     INCLUDE 'e16.event'
  24.     INCLUDE 'm16.font'
  25.     INCLUDE 'm16.memory'
  26.     INCLUDE 'm16.menu'
  27.     INCLUDE 'e16.quickdraw'
  28.     INCLUDE 'e16.textedit'
  29.     INCLUDE 'm16.textedit'
  30.     INCLUDE 'm16.util2'
  31.     INCLUDE 'm16.window'
  32.     INCLUDE 'teach.equ'
  33.  
  34. ***********************************************************************
  35. * doQuitItem
  36. *
  37. * Just set the quitFlag -- that will do    it.
  38. *
  39.     EXPORT doQuitItem
  40. doQuitItem    PROC
  41.     import quitFlag
  42.  
  43.     inc quitFlag
  44.     rts
  45.  
  46.     ENDP
  47.  
  48. ***********************************************************************
  49. * doAboutItem
  50. *
  51. * Display the vanity box.
  52. *
  53.     EXPORT doAboutItem
  54. doAboutItem    PROC
  55.  
  56.     pha
  57.     pea refIsResource*2
  58.     PushLong #0
  59.     PushLong #1
  60.     _AlertWindow
  61.     pla
  62.     rts
  63.  
  64.     ENDP
  65.  
  66. ***********************************************************************
  67. * doSelectAll
  68. *
  69. * Tell TextEdit to select all the text for the front window.
  70. *
  71.     EXPORT doSelectAll
  72. doSelectAll    PROC
  73.  
  74.     DefineStack
  75.  
  76. thisHndl    long    ;Must be at 1,s
  77.  
  78. saveDPage    word
  79. returnAddr    word
  80.  
  81. ******************
  82.  
  83.     phd    ;Save directPage register.
  84.     pha    ;Make space for thisHndl.
  85.     pha
  86.     tsc
  87.     tcd    ;Set directPage register.
  88.  
  89.     pha    ;Space for FrontWindow
  90.     pha
  91.     _FrontWindow
  92.     PushLong #MainWindowID ;FrontWindow and    MainWindowID
  93.     _GetCtlHandleFromID     ;are inputs for this.
  94. *        ;Result is now in thisHndl.
  95.  
  96.     PushLong #0
  97.     PushLong #$FFFFFFFF
  98.     pei thisHndl+2
  99.     pei thisHndl
  100.     _TESetSelection
  101.  
  102.     pla    ;Remove space for thisHndl.
  103.     pla
  104.     pld    ;Restore directPage    register
  105.     rts
  106.  
  107.     ENDP
  108.  
  109. ***********************************************************************
  110. * doChooseFont
  111. *
  112. * Use ChooseFont to    select a different font, and then have TextEdit
  113. * change the selected text in the top window.
  114. *
  115.     EXPORT doChooseFont
  116. doChooseFont    PROC
  117.     import userID
  118.  
  119.     DefineStack
  120.  
  121. thisHndl    long    ;Must be at 1,s
  122. thisStyle    block sizeofTEStyle
  123. tempHndl    long
  124.  
  125. stkFrameSize    EndLocals
  126.  
  127. saveDPage    word
  128. returnAddr    word
  129.  
  130. ******************
  131.  
  132.     phd    ;Save directPage register.
  133.     tsc    ;Make space for local variables.
  134.     sec
  135.     sbc #stkFrameSize
  136.     tcs
  137.     tcd    ;Set directPage register.
  138.  
  139.     pha    ;Create a temporary    handle
  140.     pha    ;for GetSelection style.
  141.     PushLong #20
  142.     PushWord userID
  143.     lda #0
  144.     pha    ;word of 0.
  145.     pha    ;long of 0.
  146.     pha
  147.     _NewHandle
  148.     pla
  149.     sta tempHndl
  150.     pla
  151.     sta tempHndl+2
  152.  
  153.     pha    ;Space for FrontWindow
  154.     pha
  155.     _FrontWindow    ;FrontWindow and MainWindowID
  156.     PushLong #MainWindowID ;are inputs for this.
  157.     _GetCtlHandleFromID     ;Result is now in thisHndl.
  158. *        ;This is the handle    to the TE
  159. *        ;control for the top window.
  160.  
  161.     tsc    ;Calculate pointer to thisStyle.
  162.     clc
  163.     adc #thisStyle
  164.     pha    ;Result space.
  165.     pea 0    ;Pointer to thisStyle.
  166.     pha
  167.     pei tempHndl+2
  168.     pei tempHndl
  169.     pei thisHndl+2
  170.     pei thisHndl
  171.     _TEGetSelectionStyle
  172.     pla
  173.  
  174.     pha    ;Use it as the default
  175.     pha    ;for ChooseFont.
  176.     pei thisStyle+teFont+2
  177.     pei thisStyle+teFont
  178.     pea 0
  179.     _ChooseFont
  180.     pla
  181.     sta thisStyle+teFont
  182.     pla
  183.     sta thisStyle+teFont+2
  184.  
  185.     tsc    ;Calculate pointer to thisStyle.
  186.     clc
  187.     adc #thisStyle
  188.     pea teReplaceFont+teReplaceSize+teReplaceAttributes
  189.     pea 0    ;Pointer to thisStyle.
  190.     pha
  191.     pei thisHndl+2
  192.     pei thisHndl
  193.     _TEStyleChange
  194.  
  195.     pei tempHndl+2
  196.     pei tempHndl
  197.     _DisposeHandle
  198.  
  199.     tsc    ;Remove local space.
  200.     clc
  201.     adc #stkFrameSize
  202.     tcs
  203.     pld    ;Restore directPage    register.
  204.     rts
  205.  
  206.     ENDP
  207.  
  208. ***********************************************************************
  209. * doSetFont
  210. *
  211. * Change the family    number for the selected text for the top window.
  212. *
  213.     EXPORT doSetFont
  214. doSetFont    PROC
  215.  
  216.     DefineStack
  217.  
  218. thisHndl    long    ;Must be at 1,s
  219. thisStyle    block sizeofTEStyle
  220.  
  221. stkFrameSize    EndLocals
  222.  
  223. saveDPage    word
  224. returnAddr    word
  225.  
  226. theFam    word
  227.  
  228. ******************
  229.  
  230.     phd    ;Save directPage register.
  231.     tsc
  232.     sec
  233.     sbc #stkFrameSize    ;Make space for local variables.
  234.     tcs
  235.     tcd    ;Set directPage register.
  236.  
  237.     pha    ;Space for FrontWindow
  238.     pha
  239.     _FrontWindow
  240.     PushLong #MainWindowID ;FrontWindow and    MainWindowID
  241.     _GetCtlHandleFromID     ;are inputs for this.
  242.  
  243.     lda theFam
  244.     sta thisStyle+teFont+ofamNum
  245.  
  246.     tsc    ;Calculate pointer to thisStyle.
  247.     clc
  248.     adc #thisStyle
  249.     pea teReplaceFont
  250.     pea 0    ;Pointer to thisStyle.
  251.     pha
  252.     pei thisHndl+2
  253.     pei thisHndl
  254.     _TEStyleChange
  255.  
  256.     tsc    ;Remove local variable space.
  257.     clc
  258.     adc #stkFrameSize
  259.     tcs
  260.     pld    ;Restore directPage    register.
  261.     plx    ;Keep return address.
  262.     pla    ;Remove passed parameter.
  263.     phx    ;Put return address    back
  264.     rts    ;and return.
  265.  
  266.     ENDP
  267.  
  268. ***********************************************************************
  269. * doSetSize
  270. *
  271. * Change the font size for the selected    text for the top window.
  272. *
  273.     EXPORT doSetSize
  274. doSetSize    PROC
  275.  
  276.     DefineStack
  277.  
  278. thisHndl    long    ;Must be at 1,s
  279. thisStyle    block sizeofTEStyle
  280.  
  281. stkFrameSize    EndLocals
  282.  
  283. saveDPage    word
  284. returnAddr    word
  285.  
  286. theSize    word
  287.  
  288. ******************
  289.  
  290.     phd    ;Save directPage register.
  291.     tsc
  292.     sec
  293.     sbc #stkFrameSize    ;Make space for local variables.
  294.     tcs
  295.     tcd    ;Set directPage register.
  296.  
  297.     pha    ;Space for FrontWindow
  298.     pha
  299.     _FrontWindow
  300.     PushLong #MainWindowID ;FrontWindow and    MainWindowID
  301.     _GetCtlHandleFromID     ;are inputs for this.
  302.  
  303.     shortm
  304.     lda theSize
  305.     sta thisStyle+teFont+ofontSize
  306.     longm
  307.  
  308.     tsc    ;Calculate pointer to thisStyle.
  309.     clc
  310.     adc #thisStyle
  311.     pea teReplaceSize
  312.     pea 0    ;Pointer to thisStyle.
  313.     pha
  314.     pei thisHndl+2
  315.     pei thisHndl
  316.     _TEStyleChange
  317.  
  318.     tsc    ;Remove local variable space.
  319.     clc
  320.     adc #stkFrameSize
  321.     tcs
  322.     pld    ;Restore directPage    register.
  323.     plx    ;Keep return address.
  324.     pla    ;Remove passed parameter.
  325.     phx    ;Put return address    back
  326.     rts    ;and return.
  327.  
  328.     ENDP
  329.  
  330. ***********************************************************************
  331. * doSetStyle
  332. *
  333. *
  334.     EXPORT doSetStyle
  335. doSetStyle    PROC
  336.  
  337.     DefineStack
  338.  
  339. thisHndl    long    ;Must be at 1,s
  340. thisStyle    block sizeofTEStyle
  341.  
  342. stkFrameSize    EndLocals
  343.  
  344. saveDPage    word
  345. returnAddr    word
  346.  
  347. theStyle    word
  348.  
  349. ******************
  350.  
  351.     phd    ;Save directPage register.
  352.     tsc
  353.     sec
  354.     sbc #stkFrameSize    ;Make space for local variables.
  355.     tcs
  356.     tcd    ;Set directPage register.
  357.  
  358.     pha    ;Space for FrontWindow
  359.     pha
  360.     _FrontWindow
  361.     PushLong #MainWindowID ;FrontWindow and    MainWindowID
  362.     _GetCtlHandleFromID     ;are inputs for this.
  363.  
  364.     shortm
  365.     lda theStyle
  366.     sta thisStyle+teFont+ofontStyle
  367.     longm
  368.  
  369.     ldx #teReplaceAttributes
  370.     lda theStyle
  371.     beq aa
  372.     ldx #teSwitchAttributes
  373. aa    tsc    ;Calculate pointer to thisStyle.
  374.     clc
  375.     adc #thisStyle
  376.     phx    ;Switch or replace.
  377.     pea 0    ;Pointer to thisStyle.
  378.     pha
  379.     pei thisHndl+2
  380.     pei thisHndl
  381.     _TEStyleChange
  382.  
  383.     tsc    ;Remove local variable space.
  384.     clc
  385.     adc #stkFrameSize
  386.     tcs
  387.     pld    ;Restore directPage    register.
  388.     plx    ;Keep return address.
  389.     pla    ;Remove passed parameter.
  390.     phx    ;Put return address    back
  391.     rts    ;and return.
  392.  
  393.     ENDP
  394.  
  395. ***********************************************************************
  396. * doMenu
  397. *
  398. * Function to handle all menu selections.  Examines the event.TaskData
  399. * menu item ID word    from TaskMaster (from Event Manager) and calls the
  400. * appropriate routine.  While the routine is running the menu title is
  401. * still highlighted.  After the routine    returns, we unhilight the
  402. * menu title.
  403. *
  404.     EXPORT doMenu
  405. doMenu    PROC
  406.     import event, doCloseTop, doNewWindow, doOpenWindow
  407.     import doSave, doSaveAs
  408.  
  409.     lda event+owmTaskData
  410.     cmp #AboutItem
  411.     bne aa
  412.     jsr doAboutItem
  413.     brl exit
  414.  
  415. aa    cmp #CloseItem
  416.     bne ab
  417.     jsr doCloseTop
  418.     brl exit
  419.  
  420. ab    cmp #QuitItem
  421.     bne ac
  422.     jsr doQuitItem
  423.     brl exit
  424.  
  425. ac    cmp #SelectAllItem
  426.     bne ad
  427.     jsr doSelectAll
  428.     brl exit
  429.  
  430. ad    cmp #NewItem
  431.     bne ae
  432.     jsr doNewWindow
  433.     brl exit
  434.  
  435. ae    cmp #OpenItem
  436.     bne af
  437.     jsr doOpenWindow
  438.     brl exit
  439.  
  440. af    cmp #SaveItem
  441.     bne ag
  442.     jsr doSave
  443.     brl exit
  444.  
  445. ag    cmp #SaveAsItem
  446.     bne ah
  447.     jsr doSaveAs
  448.     brl exit
  449.  
  450. ah    cmp #PageSetupItem
  451.     bne ai
  452. *        ;Not implemented yet.
  453.     brl exit
  454.  
  455. ai    cmp #PrintItem
  456.     bne aj
  457. *        ;Not implemented yet.
  458.     brl exit
  459.  
  460. aj    cmp #PlainItem
  461.     bne ak
  462.     pea 0
  463.     jsr doSetStyle
  464.     brl exit
  465.  
  466. ak    cmp #BoldItem
  467.     bne al
  468.     pea boldMask
  469.     jsr doSetStyle
  470.     brl exit
  471.  
  472. al    cmp #ItalicItem
  473.     bne am
  474.     pea italicMask
  475.     jsr doSetStyle
  476.     brl exit
  477.  
  478. am    cmp #UnderlineItem
  479.     bne an
  480.     pea underlineMask
  481.     jsr doSetStyle
  482.     brl exit
  483.  
  484. an    cmp #ShadowItem
  485.     bne ao
  486.     pea shadowMask
  487.     jsr doSetStyle
  488.     brl exit
  489.  
  490. ao    cmp #OutlineItem
  491.     bne ap
  492.     pea outlineMask
  493.     jsr doSetStyle
  494.     brl exit
  495.  
  496. ap    cmp #Size8Item
  497.     bne aq
  498.     pea 8
  499.     jsr doSetSize
  500.     brl exit
  501.  
  502. aq    cmp #Size10Item
  503.     bne ar
  504.     pea 10
  505.     jsr doSetSize
  506.     brl exit
  507.  
  508. ar    cmp #Size12Item
  509.     bne as
  510.     pea 12
  511.     jsr doSetSize
  512.     brl exit
  513.  
  514. as    cmp #Size16Item
  515.     bne at
  516.     pea 16
  517.     jsr doSetSize
  518.     brl exit
  519.  
  520. at    cmp #Size20Item
  521.     bne au
  522.     pea 20
  523.     jsr doSetSize
  524.     brl exit
  525.  
  526. au    cmp #Size24Item
  527.     bne av
  528.     pea 24
  529.     jsr doSetSize
  530.     brl exit
  531.  
  532. av    cmp #ChooseFontItem
  533.     bne aw
  534.     jsr doChooseFont
  535.     brl exit
  536.  
  537. aw    cmp #FirstFontItem
  538.     bcc exit
  539.     pha    ;Result space.
  540.     pha    ;Item num.
  541.     _ItemID2FamNum    ;Fam num now on stack.
  542.     jsr doSetFont
  543.  
  544. exit    pea 0
  545.     lda event+owmTaskData+2
  546.     pha
  547.     _HiliteMenu
  548.  
  549.     rts
  550.  
  551.     ENDP
  552.  
  553. ***********************************************************************
  554. * setupMenus
  555. *
  556. * Function to install our menu titles and their items in the system
  557. * menu bar and to redraw it so we can see them.
  558. *
  559.     EXPORT setupMenus
  560. setupMenus    PROC
  561.  
  562.     pha
  563.     pha
  564.     pea refIsResource
  565.     PushLong #1
  566.     PushLong #0
  567.     _NewMenuBar2
  568.     _SetSysBar
  569.  
  570.     PushLong #0
  571.     _SetMenuBar
  572.  
  573.     pea AppleMenuID
  574.     _FixAppleMenu
  575.  
  576.     pea FontMenuID
  577.     pea FirstFontItem
  578.     pea 0
  579.     _FixFontMenu
  580.  
  581.     pha
  582.     _FixMenuBar
  583.     pla
  584.  
  585. * Rather than drawing menu bar here, I rely on FixFrontW to    do it first.
  586.  
  587.     rts
  588.  
  589.     ENDP
  590.  
  591.     END
  592.